//Luogu:392844 the second year in CSP-S rp++
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T,n,a[1000001],maxa=-1,color[1000001];
map<ll,ll> m;
void dfs(ll idx){
    if(idx==n+1){
        ll res=0;
        for(ll i=2;i<=n;i++){
            ll f=1;
            for(ll j=i-1;j>=1;j--){
                if(color[i]==color[j]){
                    if(a[i]==a[j]) res+=a[i];
                    f=0;
                }
                if(f==0) break;
            }
        }
        maxa=max(maxa,res);
        return;
    }
    color[idx]=1;
    dfs(idx+1);
    color[idx]=2;
    dfs(idx+1);
    color[idx]=0;
    return;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%lld",&T);
    while(T--){
        maxa=-1;
        memset(a,0,sizeof a);
        memset(color,0,sizeof color);
        scanf("%lld",&n);
        for(ll i=1;i<=n;i++) scanf("%lld",a+i);
        if(n<=15){
            dfs(1);
            printf("%lld\n",maxa);
        }
        else{
            ll res=0;
            for(ll i=1;i<=n;i++) m[a[i]]++;
            for(ll i=1;i<=n;i++){
                res+=a[i]*(m[a[i]]-1);
                m[a[i]]=1;
            }
            printf("%lld\n",res);
        }
    }
    return 0;
}
/*
16:00 start to get the 20 pts
16:20 over
rp++;
*/
